<?php

/**
 * Services are globally registered in this file
 */
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\DI\FactoryDefault;
use Phalcon\Session\Adapter\Files as SessionAdapter;

/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new FactoryDefault();

/**
 * The URL component is used to generate all kind of urls in the application
 */
$di['url'] = function ()
{
    $url = new UrlResolver();
    $url->setBaseUri('/ChanTienGioi/');

    return $url;
};

/**
 * Start the session the first time some component request the session service
 */
$di->set('session', function ()
{
    $memcache = new SessionAdapter(array(
        'host'       => 'localhost', // mandatory
        'port'       => 11211, // optional (standard: 11211)
        'lifetime'   => 172800, // optional (standard: 8600)
        'prefix'     => 'chantiengioi', // optional (standard: [empty_string]), means memcache key is my-app_31231jkfsdfdsfds3
        'persistent' => false            // optional (standard: false)
    ));
    $memcache->start();
    return $memcache;
});

//Set Cache
$di->set('cache', function ()
{
    $frontCache = new Phalcon\Cache\Frontend\Data(array(
        "lifetime" => 3600
    ));

    $cache = new Phalcon\Cache\Backend\Memcache($frontCache, array(
        "servers" => array(
            array(
                "host"   => "localhost",
                "port"   => "11211",
                "weight" => "1"
            )
        )
    ));
    return $cache;
});

//Set Link CSS
$di->set('assets', function ()
{
    return new Phalcon\Assets\Manager();
}, true);

//Set Config
$di->set('config', function ()
{
    return include __DIR__ . "/config.php";
}, true);

//Config Router
$di->set('router', function ()
{
    return include __DIR__ . "/router.php";
}, true);
